<template>
	<view>
		<!-- h5端弹出小程序码 -->
		<uni-popup ref="openQrcode" type="center">
			<view class="open-qrcode">
				<!--小程序二维码-->
				<view class="content">
					<view class="title">扫描进入小程序</view>
					<view v-if="qrcodeUrl">
						<image class="image" :src="qrcodeUrl" mode="widthFix"></image>
					</view>
					<view v-else>
						加载中...
					</view>
				</view>
				<view class="close-icon" @click="closeQrcode()">
					<text class="iconfont">&#xe622;</text>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>

	export default {
		props: {
		},
		data() {
			return {
				qrcodeUrl:""
			}
		},
		created() {
		},
		methods: {
			/**
			 * 跳转小程序
			 * @param {Object} link
			 */
			toMiniprogram(link) {
				//console.log(link);
				let that = this
				// 请求数据
				let url = 'entry/site/tominiprogram'
				//#ifdef MP-WEIXIN
				url = 'entry/wxapp/tominiprogram'
				//#endif
				//#ifdef H5
				url = 'entry/site/tominiprogram'
				//#endif
				// 获取数据
				this.util.request({
					url: url,
					data: {
						action: 'detail',
						id: link.param.id
					},
					success: function(res) {
						if (res.data.code == 200) {
							// #ifdef MP-WEIXIN
							wx.navigateToMiniProgram({
								appId: res.data.data.appid,
							})
							// #endif
							// #ifdef H5
							that.qrcodeUrl = res.data.data.qrcode_400
							console.log(that.cdnUrl)
							that.showQrcode()
							// #endif
						}
					}
				})
			
			},
			
			/**
			 * 弹出小程序二维码
			 */
			showQrcode() {
				this.$refs.openQrcode.open()
			},
			
			/**
			 * 关闭小程序二维码
			 */
			closeQrcode() {
				this.$refs.openQrcode.close()
			},
		}
	}
</script>

<style lang="scss">
	.open-qrcode {
	
		.content {
			background-color: #fff;
			border-radius: 10rpx;
			overflow: hidden;
			width: 480rpx;
			padding: 20rpx;
	
			.title {
				text-align: center;
				font-size: 32rpx;
				font-weight: 700;
				line-height: 52rpx;
			}
	
			.image {
				max-width: 100%;
			}
		}
	
		.close-icon {
			padding-top: 32rpx;
			text-align: center;
			color: #fff;
	
			.iconfont {
				font-size: 64rpx;
			}
		}
	}
</style>
